package com.lesso.lll.sunflower.employee.controller;

import com.lesso.lll.sunflower.employee.entity.Employee;
import com.lesso.lll.sunflower.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工控制器
 */
@RestController
@RequestMapping("/api/employee")
@Api(tags = "EmployeeController", description = "员工管理")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @ApiOperation("新增员工")
    @PostMapping("/add")
    public CommonResult<Long> addEmployee(@RequestBody Employee employee) {
        Long employeeId = employeeService.addEmployee(employee);
        return CommonResult.success(employeeId);
    }

    @ApiOperation("修改员工信息")
    @PostMapping("/update")
    public CommonResult<Boolean> updateEmployee(@RequestBody Employee employee) {
        boolean result = employeeService.updateEmployee(employee);
        return CommonResult.success(result);
    }

    @ApiOperation("员工离职")
    @PostMapping("/resign/{employeeId}")
    public CommonResult<Boolean> resignEmployee(@PathVariable Long employeeId) {
        boolean result = employeeService.resignEmployee(employeeId);
        return CommonResult.success(result);
    }

    @ApiOperation("绑定考勤设备")
    @PostMapping("/bind/devices/{employeeId}")
    public CommonResult<Boolean> bindAttendanceDevices(@PathVariable Long employeeId, 
                                                        @RequestBody List<Long> deviceIds) {
        boolean result = employeeService.bindAttendanceDevices(employeeId, deviceIds);
        return CommonResult.success(result);
    }

    @ApiOperation("绑定考勤规则")
    @PostMapping("/bind/rule/{employeeId}")
    public CommonResult<Boolean> bindAttendanceRule(@PathVariable Long employeeId,
                                                    @RequestParam Long ruleId,
                                                    @RequestParam String effectiveDate) {
        boolean result = employeeService.bindAttendanceRule(employeeId, ruleId, effectiveDate);
        return CommonResult.success(result);
    }
}    